package com.jwsoft.manager.core.dao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jwsoft.manager.common.vo.common.recruitStudent.SyncStudentQueryVO;
import com.jwsoft.manager.common.vo.common.recruitStudent.SyncStudentVO;
import com.jwsoft.manager.core.dao.mapper.EduSyncZjApplyMapper;
import com.jwsoft.manager.core.dao.mapper.EduSyncZjApproveMapper;
import com.jwsoft.manager.core.dao.model.EduSyncZjApply;
import com.jwsoft.manager.core.dao.model.EduSyncZjEnroll;
import com.jwsoft.manager.core.dao.mapper.EduSyncZjEnrollMapper;
import com.jwsoft.manager.core.dao.service.EduSyncZjEnrollService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 省报名录取专库同步情况表服务实现类
 *
 * @author chenzh
 * @since 2023-07-25
 */
@Service
public class EduSyncZjEnrollServiceImpl extends ServiceImpl<EduSyncZjEnrollMapper, EduSyncZjEnroll> implements EduSyncZjEnrollService {

    @Autowired
    public EduSyncZjApplyMapper eduSyncZjApplyMapper;

    @Override
    public List<SyncStudentVO> queryNoCreate(SyncStudentQueryVO syncStudentQueryVO) {
        return baseMapper.queryNoCreate(syncStudentQueryVO);
    }

    @Override
    public List<EduSyncZjApply> getSyncDeleteEnrollList(Integer year, String syncType) {
        QueryWrapper<EduSyncZjApply> applyQueryWrapper = new QueryWrapper<>();
        applyQueryWrapper.lambda().eq(EduSyncZjApply::getTheYear, year)
                .notExists("SELECT 1 from edu_student_enroll a where edu_sync_zj_apply.id_number = a.idcard and a.enroll_status = 2 and a.del = '0' and a.year =" +year);
        if ("2".equalsIgnoreCase(syncType)){
            applyQueryWrapper.lambda().notExists("SELECT 1 from edu_sync_zj_delete  a where edu_sync_zj_apply.id_number = a.id_number and a.del = 0 and a.the_year = " +year);
        }
        List<EduSyncZjApply> syncDeleteApplyList = eduSyncZjApplyMapper.selectList(applyQueryWrapper);
        return syncDeleteApplyList != null ? syncDeleteApplyList: new ArrayList<>();
    }
}
